import {
  BasicColumn
} from '/@/components/Table';
import {
  FormSchema
} from '/@/components/Table';
import {
  rules
} from '/@/utils/helper/validator';
import {
  render
} from '/@/utils/common/renderUtils';
//列表数据
export const columns: BasicColumn[] = [{
    title: '编码',
    align: "center",
    sorter: true,
    dataIndex: 'deviceCode',
    width: 100
  },
  {
    title: '名称',
    align: "center",
    sorter: true,
    dataIndex: 'deviceName'
  },
  {
    title: '规格',
    align: "center",
    dataIndex: 'spec',
    width: 80
  },
  {
    title: '班组',
    align: "center",
    dataIndex: 'teamGroupName'
  },
  {
    title: '发起人',
    align: "center",
    dataIndex: 'promoterName',
    width: 90
  },
  {
    title: '停机类型',
    align: "center",
    dataIndex: 'shutdownType',
    customRender: ({
      text
    }) => {
      return text == 0 ? "年度维修" : text == 1 ? '季度维修' : text == 2 ? "突发异常" : ''
    },
    width: 100
  },
  {
    title: '停机原因',
    align: "center",
    dataIndex: 'shutdownReason',
    width: 100
  },
  {
    title: '申报时间',
    align: "center",
    dataIndex: 'declareTime',
    width: 180
  },
  {
    title: '处理时间',
    align: "center",
    dataIndex: 'handleTime',
    width: 180
  },
  {
    title: '结束时间',
    align: "center",
    dataIndex: 'settlementTime',
    width: 180
  },
  {
    title: '响应时间',
    align: "center",
    dataIndex: 'respondentTime',
    width: 180
  },
  {
    title: '停机时间',
    align: "center",
    dataIndex: 'shutdownTime',
    width: 180
  },
  {
    title: '维修时长',
    align: "center",
    dataIndex: 'maintenanceDuration',
    width: 100
  },
  {
    title: '措施类型',
    align: "center",
    dataIndex: 'measureType',
    width: 100
  },
  {
    title: '解决方案',
    align: "center",
    dataIndex: 'solution',
    width: 100
  },
  {
    title: '响应人',
    align: "center",
    dataIndex: 'respondentName',
    width: 100
  },
  {
    title: '处理人',
    align: "center",
    dataIndex: 'handleName',
    width: 100
  },
  {
    title: '单据状态',
    align: "center",
    dataIndex: 'billStatus',
    width: 100
  },
  {
    title: '备注',
    align: "center",
    dataIndex: 'remark'
  },
  {
    title: '第三方编码',
    align: "center",
    dataIndex: 'thirdPartyCode',
    width: 110,
    ifShow: false
  },
];
//查询数据
export const searchFormSchema: FormSchema[] = [{
    label: "编码",
    field: 'deviceCode',
    component: 'Input',
    colProps: {
      span: 6
    },
  },
  {
    label: "名称",
    field: 'deviceName',
    component: 'Input',
    colProps: {
      span: 6
    },
  },
  {
    label: "班组",
    field: 'teamGroupName',
    component: 'Input',
    colProps: {
      span: 6
    },
  },
];
//表单数据
export const formSchema: FormSchema[] = [{
    label: 'ID',
    field: 'deviceId',
    component: 'Input',
    show: false
  },
  {
    label: '编码',
    field: 'deviceCode',
    component: 'Input',
  },
  {
    label: '名称',
    field: 'deviceName',
    component: 'Input',
    slot: 'deviceSlot',
    dynamicRules: ({
      model,
      schema
    }) => {
      return [{
        required: true,
        message: '请输入名称!'
      }, ];
    },
  },
  {
    label: '规格',
    field: 'spec',
    component: 'Input',
  },
  {
    label: '班组ID',
    field: 'teamGroupId',
    component: 'Input',
    show: false
  },
  {
    label: '班组',
    field: 'teamGroupId',
    component: 'JSelectDept',
    componentProps: ({}) => {
      return {
        multiple: false,
        showButton: false,
        checkable: false
      }
    },
  },
  {
    label: '发起人ID',
    field: 'promoterId',
    component: 'Input',
    show: false
  },
  {
    label: '发起人',
    field: 'promoterId',
    component: 'JSelectUserByDept',
    componentProps: ({}) => {
      return {
        stringToNumber: true,
        isRadioSelection: true,
        showButton: false,
        rowKey: 'id'
      }
    }
  },
  {
    label: '停机类型',
    field: 'shutdownType',
    component: 'Select',
    dynamicRules: ({
      model,
      schema
    }) => {
      return [{
        required: true,
        message: '请选择停机类型'
      }, ];
    },
    componentProps: {
      options: [{
        label: '年度维修',
        value: 0
      }, {
        label: '季度维修',
        value: 1
      }, {
        label: '突发异常',
        value: 2
      }],
      stringToNumber: true,
    }
  },
  {
    label: '停机原因',
    field: 'shutdownReason',
    component: 'Input',
  },
  {
    label: '申报时间',
    field: 'declareTime',
    component: 'DatePicker',
    componentProps: {
      showTime: true,
      valueFormat: 'YYYY-MM-DD HH:mm:ss'
    },
    dynamicRules: ({ model }) => rules.declareTime(model.handleTime, false),
  },
  {
    label: '处理时间',
    field: 'handleTime',
    component: 'DatePicker',
    componentProps: {
      showTime: true,
      valueFormat: 'YYYY-MM-DD HH:mm:ss'
    },
    dynamicRules: ({ model }) => rules.handleTime(model.respondentTime, false),
  },
  {
    label: '结束时间',
    field: 'settlementTime',
    component: 'DatePicker',
    componentProps: {
      showTime: true,
      valueFormat: 'YYYY-MM-DD HH:mm:ss'
    },
    dynamicRules: ({ model }) => rules.settlementTime(model.handleTime, false),
  },
  {
    label: '响应时间',
    field: 'respondentTime',
    component: 'DatePicker',
    componentProps: {
      showTime: true,
      valueFormat: 'YYYY-MM-DD HH:mm:ss'
    },
    dynamicRules: ({ model }) => rules.respondentTime(model.shutdownTime, false),
  },
  {
    label: '停机时间',
    field: 'shutdownTime',
    component: 'DatePicker',
    componentProps: {
      showTime: true,
      valueFormat: 'YYYY-MM-DD HH:mm:ss'
    },
    dynamicRules: ({ model }) => rules.shutdownTime(model.respondentTime, false),
  },
  {
    label: '维修时长',
    field: 'maintenanceDuration',
    component: 'InputNumber',
  },
  {
    label: '措施类型',
    field: 'measureType',
    component: 'Input',
  },
  {
    label: '解决方案',
    field: 'solution',
    component: 'Input',
  },
  {
    label: '响应人ID',
    field: 'respondentId',
    component: 'Input',
    show: false
  },
  {
    label: '响应人',
    field: 'respondentId',
    component: 'JSelectUserByDept',
    componentProps: ({}) => {
      return {
        stringToNumber: true,
        isRadioSelection: true,
        showButton: false,
        rowKey: 'id'
      }
    }
  },
  {
    label: '处理人ID',
    field: 'handleId',
    component: 'Input',
    show: false
  },
  {
    label: '处理人',
    field: 'handleId',
    component: 'JSelectUserByDept',
    componentProps: ({}) => {
      return {
        stringToNumber: true,
        isRadioSelection: true,
        showButton: false,
        rowKey: 'id'
      }
    }
  },
  // {
  //   label: '单据状态',
  //   field: 'billStatus',
  //   component: 'InputNumber',
  // },
  {
    label: '备注',
    field: 'remark',
    component: 'Input',
  },
  {
    label: '第三方编码',
    field: 'thirdPartyCode',
    component: 'Input',
    ifShow: false
  },
  // TODO 主键隐藏字段，目前写死为ID
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false
  },
];



/**
 * 流程表单调用这个方法获取formSchema
 * @param param
 */
export function getBpmFormSchema(_formData): FormSchema[] {
  // 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
  return formSchema;
}
